/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETFOfflineSource
  \brief to process offline data, an abstract base class
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-09-28
  \date 2021-09-28 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-09-28   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFOfflineSource_h
#define ETFOfflineSource_h

#include <map>
#include <string>
#include "FairOnlineSource.h"

using std::map;
using std::string;

class ETFUnpacker;

/// the following values correspond to
enum class SourceType : short{
  kGENERAL, ///< ETFOfflineSource
  kPXISOURCE, ///< ETFPXIOfflineSource
  kVMESOURCE, ///< ETFVMEOfflineSource
  kMIXEDSOURCE ///< ETFMixedOfflineSource
}; ///< source type

class ETFOfflineSource : public FairOnlineSource{
public:
  ETFOfflineSource();
  virtual ~ETFOfflineSource();

  virtual int ReadEvent(UInt_t i = 0); ///< read event i
  virtual void Close(); ///< close the input file
  virtual void PrintSummary(); ///< print unpacking summary
  SourceType GetType() const{ return fType; }
  virtual const TString ROOTFileName() const = 0; ///< generate a root file name

  ClassDef(ETFOfflineSource, 0); ///< to process offline data

protected:
  void SetType(SourceType type){ fType = type; }
  virtual void FinishEvent() = 0; // do something (e.g. print sth.) upon finishing an event
  /// \param isStop: whether to issue an error if returning false
  static bool IsPXIFileName(const string &file, bool isStop = false);
  static bool IsVMEFileName(const string &file, bool isStop = false);

  map<ETFUnpacker *, FILE *> fMap; ///< map of unpacker and its data file
  SourceType fType; ///< source type

  int fEventCnt;
};

#endif
